﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace HotelManager.Views
{
    public partial class Form_Login : Skin_DevExpress
    {
        public Form_Login()
        {
            InitializeComponent();
        }

        private void Login_Form_Load(object sender, EventArgs e)
        {

        }

        public bool isLoginSuccessful = false;
        private void button1_Click(object sender, EventArgs e)
        {
            if (skinTextBox1.Text == string.Empty)
            {
                MessageBox.Show("请输入登录的账户！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                skinTextBox1.Focus();
                return;
            }
            if (skinTextBox2.Text == string.Empty)
            {
                MessageBox.Show("请输入登录的密码！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                skinTextBox2.Focus();
                return;
            }
            if (skinTextBox1.Text.Contains("'") || skinTextBox2.Text.Contains("'"))
            {
                MessageBox.Show("输入不合规，请重新输入！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (DB.GetData("select 管理员ID from 管理员表 where 账户='"
                + skinTextBox1.Text + "'and 密码='" + skinTextBox2.Text + "'") == null)
            {
                MessageBox.Show("用户名或者密码错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            isLoginSuccessful = true;
            Utils.User user = new Utils.User();
            DataView dv = DB.GetDs("select 管理员ID,名称 from 管理员表 where 账户='" + skinTextBox1.Text + "'").Tables[0].DefaultView;
            user.UserID = dv[0][0].ToString();
            user.UserName = dv[0][1].ToString();
            Utils.GlobalData.LoginUser = user;
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
